from typing import Optional
from datetime import datetime
from pydantic import BaseModel, Field

class UserKeyCreate(BaseModel):
    key: str = Field(..., description="Key")
    remainder: int = Field(..., description="Remainder")

class UserKeyUpdate(BaseModel):
    key: Optional[str] = Field(None, description="Key")
    remainder: Optional[int] = Field(None, description="Remainder")


class UsedLogCreate(BaseModel):
    key: str = Field(..., description="Key")
    lastime: datetime = Field(..., description="Lastime")
    ip: str = Field(..., description="IP")

class UsedLogUpdate(BaseModel):
    key: Optional[str] = Field(None, description="Key")
    lastime: Optional[datetime] = Field(None, description="Lastime")
    ip: Optional[str] = Field(None, description="IP")

# 新增API请求模型
class RealVideo2TextRequest(BaseModel):
    key: str = Field(..., description="密钥")
    url: str = Field(..., description="抖音视频真实下载地址")

class Video2TextRequest(BaseModel):
    key: str = Field(..., description="密钥")
    url: str = Field(..., description="抖音视频分享url")

class Share2RealUrlRequest(BaseModel):
    key: str = Field(..., description="密钥")
    share_text: str = Field(..., description="抖音的视频分享链接")

class ImitateTextRequest(BaseModel):
    key: str = Field(..., description="密钥")
    text: str = Field(..., description="文案")

# 新增API响应模型
class Video2TextResponse(BaseModel):
    text: str = Field(..., description="从视频中提取的文本内容，包含换行符")

class Share2RealUrlResponse(BaseModel):
    text: str = Field(..., description="视频的真实下载url")

class ImitateTextResponse(BaseModel):
    text: str = Field(..., description="根据原文案生成的仿写文案")

class ErrorResponse(BaseModel):
    detail: str = Field(..., description="错误详细信息")

# 去水印API请求模型
class RemoveWatermarkRequest(BaseModel):
    key: str = Field(..., description="密钥")
    url: str = Field(..., description="视频URL或分享文本")
    prefer_local: Optional[bool] = Field(False, description="是否优先使用本地逻辑处理")

# 去水印API响应模型
class RemoveWatermarkResponse(BaseModel):
    success: bool = Field(..., description="处理是否成功")
    clean_video_url: Optional[str] = Field(None, description="去水印后的视频URL")
    original_video_info: Optional[dict] = Field(None, description="原始视频信息")
    processing_time: float = Field(..., description="处理耗时（秒）")
    used_fallback: Optional[bool] = Field(None, description="是否使用了降级处理")
